﻿using MediatR;
using T.Vehicleservice.API.Application.Command.MaintenanceRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.MaintenanceRecordCommandHander
{
    /// <summary>
    /// 批删保养记录
    /// </summary>
    public class MaintenanceRecordDeleteAllCommandHander : IRequestHandler<MaintenanceRecordDeleteAllCommand, int>
    {
        private readonly IMaintenanceRecordRepository _maintenanceRecordRepository;
        public MaintenanceRecordDeleteAllCommandHander(IMaintenanceRecordRepository managementRecordRepository)
        {
            _maintenanceRecordRepository = managementRecordRepository;
        }
        public async Task<int> Handle(MaintenanceRecordDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var MainIds = request.ids;
            foreach (var item in MainIds)
            {
                var DelAll = _maintenanceRecordRepository.GetModelAsync(item).Result;
                DelAll.IsDeleted = true;
              
                await _maintenanceRecordRepository.UpdateAsync(DelAll);
            }
            return 1;
        }
    }
}
